using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Markup;
using Common;
using Common.Enum;
using SProject.Paramter;

namespace ProjectView.Windows
{
	public partial class ProjectGainInfoWindow : Window, IComponentConnector
	{
		private ObservableCollection<BasicOptionItem> Items;

		public ProjectGainInfoWindow()
		{
			InitializeComponent();
		}

		public void setData(ObservableCollection<BasicOptionItem> Items, EProjectType type = EProjectType.AQ)
		{
			this.Items = Items;
			List<BasicOptionItem> list = new List<BasicOptionItem>();
			foreach (BasicOptionItem Item in Items)
			{
				BasicOptionItem basicOptionItem = new BasicOptionItem();
				switch (type)
				{
				case EProjectType.AQ:
					colBasicGain.Visibility = Visibility.Visible;
					basicOptionItem = new BasicOptionItem();
					base.Title = Utility.GetMessage("title_amp_gain");
					break;
				case EProjectType.Melt:
					colMeltGain.Visibility = Visibility.Visible;
					basicOptionItem = new MeltingOptionItem();
					base.Title = Utility.GetMessage("title_melt_gain");
					break;
				}
				basicOptionItem.Copy(Item);
				list.Add(basicOptionItem);
			}
			myGrid.ItemsSource = list;
		}

		private void btnOK_Click(object sender, RoutedEventArgs e)
		{
			foreach (BasicOptionItem data in myGrid.ItemsSource as List<BasicOptionItem>)
			{
				if (colBasicGain.Visibility == Visibility.Visible)
				{
					Items.Where((BasicOptionItem s) => s.TargetName.Equals(data.TargetName)).FirstOrDefault().AMPGain = data.AMPGain;
				}
				else if (colMeltGain.Visibility == Visibility.Visible)
				{
					((MeltingOptionItem)Items.Where((BasicOptionItem s) => s.TargetName.Equals(data.TargetName)).FirstOrDefault()).MeltGain = ((MeltingOptionItem)data).MeltGain;
				}
			}
			Close();
		}

		private void btnCancel_Click(object sender, RoutedEventArgs e)
		{
			Close();
		}
	}
}
